<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>


<style type="text/css">
<!--
#style {
	
	border-top-width: 1px;
	border-right-width: 1px;
	border-bottom-width: 1px;
	border-left-width: 1px;
	border-top-style: none;
	border-right-style: solid;
	border-bottom-style: none;
	border-left-style: solid;
	border-top-color: #F96;
	border-right-color: #F96;
	border-bottom-color: #F96;
	border-left-color: #F96;
	background:#FFC;
}
-->
</style>
</head>

<body>
<?php if (isset($_POST["txttim"]) || isset($_GET["txttim"])) { 
if (isset($_POST["txttim"]))
{
	$tim=$_POST["txttim"];
}
else
{
	$tim=$_GET["txttim"];
}

?>


<table id="style" width="537">
<tr><td align="center" bgcolor="#CCFF66"> Bạn Đã Tìm Từ :  <span> <?php echo $tim ?></span></td></tr>

<?php
  require_once("connect/dbcon.php");
  $sosp=3*3;//số sp trên 1 trang
  $nhom=3;//số trang trong 1 nhóm trang
  
  if(!isset($_GET["tst"])) {
  $kq=mysql_query("select * from may where TenMay like '%$tim%'",$link);
  $tongsotrang=ceil(mysql_num_rows($kq)/$sosp);
  $tongsonhom=ceil($tongsotrang/$nhom);
  }

  else
  {
  $tongsotrang=intval($_GET["tst"]);
   $tongsonhom=ceil($tongsotrang/$nhom);//giữ lại tồng số trang
  }
  //$p trang đang xem
  //%n nhóm đang xem
  if (!isset($_GET["p"]))
  { 
      if (!isset($_GET["n"]))
	  {$p=1; $n=1; }
	  else
	  //có n mà ko có p, người xem click zô n ( dấu chuyển )
	  {$n=intval($_GET["n"]);
	   $p=$n*$nhom-$nhom+1;  }// tính ra trang đầu tiên của nhóm n
  
  }
  else
  //có p mà ko có n, người xem click vào p ( số )
  {
  	$p=intval($_GET["p"]);
	$n=ceil($p/$nhom);
  }
  
  
  
  
  $x=($p-1)*$sosp;
  $s="select * from may where TenMay like '%$tim%' limit $x,$sosp";
  $kq=mysql_query($s,$link);
  while($dong=mysql_fetch_array($kq))
  {
  ?>
<tr>
    <td width="176" valign="top"><div align="center">
   
    <img width="80" height="80" src="images/product/<?php echo $dong["UrlHinh"]; ?>" /><br />
    <?php echo $dong["TenMay"]; ?><br />
     <a href="index.php?ACT=chitiet&idMay=<?php echo $dong["idMay"]; ?>"><img src="images/intro/button_details.gif" width="74" height="17" /></a><br />
    Giá : <font color="#FF0000"><?php echo number_format($dong["Gia"]); ?></font> VND
    </div></td>
    
     <!-- cot thu 2 -->
     <?php
	 if ($dong=mysql_fetch_array($kq))
	 {
	 ?>
    <td width="176" valign="top"><div align="center">
    
    <img width="80" height="80" src="images/product/<?php echo $dong["UrlHinh"]; ?>" /><br />
    <?php echo $dong["TenMay"]; ?><br />
     <a href="index.php?ACT=chitiet&idMay=<?php echo $dong["idMay"]; ?>"><img src="images/intro/button_details.gif" width="74" height="17" /></a><br />
    Giá : <font color="#FF0000"><?php echo number_format($dong["Gia"]); ?></font> VND
    </div></td>
    <?php }		 ?>

     <!-- cot thu 3 -->
       <?php
	 if ($dong=mysql_fetch_array($kq))          // kiem tra xem co du lieu ko thi do? vao cot.
	 {
	 ?>
    <td width="176" valign="top"><div align="center">
    
    <img width="80" height="80" src="images/product/<?php echo $dong["UrlHinh"]; ?>" /><br />
    <?php echo $dong["TenMay"]; ?><br />
     <a href="index.php?ACT=chitiet&idMay=<?php echo $dong["idMay"]; ?>"><img src="images/intro/button_details.gif" width="74" height="17" /></a><br />
    Giá : <font color="#FF0000"><?php echo number_format($dong["Gia"]); ?></font> VND
    </div></td>
    <?php }	 ?>
      </div>
    
      
      
  </tr><?php } ?>
</table>

<p align="center">

<?php if ($n>1) {
	$n1=$n-1;
?>
<a href="index.php?ACT=tim&txttim=<?php echo $tim ?>&n=<?php echo $n1; ?>&tst=<?php echo $tongsotrang; ?>"><<</a>&nbsp;

<?php } ?>	

<?php
$dau=($n-1)*$nhom+1;//trang đầu nhóm đang xem
if ($n<$tongsonhom)//chưa là nhóm cuối
{$cuoi=$dau+$nhom-1;//trang cuối nhóm đang xem
}
else
//nếu là tran cuối
{$cuoi=$tongsotrang;}
for($i=$dau;$i<=$cuoi;$i++)
{ if ($i==$p)
   { echo $i."&nbsp;";
   }
   else
   {
 ?>
 <a href="index.php?ACT=tim&txttim=<?php echo $tim ?>&p=<?php echo $i; ?>&tst=<?php echo $tongsotrang; ?>"><?php echo $i; ?></a>
<?php
   }
}
?>   
<?php if ($n<$tongsonhom) {
	$n2=$n+1;
?>
<a href="index.php?ACT=tim&txttim=<?php echo $tim ?>&n=<?php echo $n2; ?>&tst=<?php echo $tongsotrang; ?>">>></a>&nbsp;
<?php } ?>
</p>
<?php }?>
</body>
</html>